package p.ithorns.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import p.ithorns.framework.feign.enhance.EnableFeignService;
import p.ithorns.framework.feign.enhance.FeignController;

/**
 * ExampleApp
 *
 * @author Ht.L
 * @date 2024-03-08 14:31
 * @since 1.0.0
 */
@SpringBootApplication
@EnableFeignService({"p.ithorns.example", "p.ithorns.framework.feign"})
public class ProducerApp implements CommandLineRunner {

    @Autowired
    ApplicationContext ctx;

    public static void main(String[] args) {
        SpringApplication.run(ProducerApp.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        String[] beanNamesForType = ctx.getBeanNamesForType(FeignController.class);
        String[] beanDefinitionNames = ctx.getBeanDefinitionNames();
        for (String beanDefinitionName : beanNamesForType) {
            System.out.println(beanDefinitionName);

            Object obj = ctx.getBean(beanDefinitionName);
            if (obj instanceof HelloApi) {
                HelloApi bean = (HelloApi) obj;
                System.out.println(bean.param("sss"));
            }
        }
        System.out.println("=====> 启动了");
    }

}